<?php

namespace App\Winged\Evaluation\Controllers ;

use App\Winged\Components\Content;
use App\Winged\Evaluation\Api\Api;
use App\Winged\Evaluation\Api\Consult;
use Illuminate\Http\Request;

class ConsultController extends BaseController{


    public function index()
    {
        return $this->Content(function(Content $content){
            $view = view('winged.evaluation::index');
            $content->body($view);
        });
    }

    /**
     * @param \Illuminate\Http\Request $request
     * 中转接口
     * @return \Illuminate\Http\JsonResponse
     */
    public function transfer(Request $request)
    {
        $path   = $request->input('path');
        $params = $request->input('params' , null);
        $method = strtoupper($request->input('method' , 'GET'));
        try {
            list($status , $content) = Api::doTransfer($path ,$method , $params);
            return response()
                ->json(['status' => $status, 'content' => $content]);
        }
        catch (\Exception $e) {
            return response()->json(['msg' => $e->getMessage() , 'status' => 500]);
        }
    }
}
